package com.deyuanyun.pic.settings.domain.util;

import java.util.List;

/**
 * 
 * Domain实体类集合操作。
 * 
 * @author ChenKui
 * @date 2016-06-24
 * 
 */
public class DomainCollectionsUtil {

    /**
     * 获取一个集合对象中的某一个字段的集合
     * 
     * @param list
     * @param fieldName
     * @return
     */
    public static String[] toOneFieldValues(List<?> list,String fieldName){
        
        String[] items = new String[list.size()];
        for (int i = 0; i < list.size(); i++) {
            Object item = list.get(i);
            String val = (String)DomainFieldReflectUtil.getFieldValue(item, fieldName);
            items[i] = val;
        }
        return items;
    }
    

    /**
     * 获取一个集合对象中的某一个字段的集合
     * 
     * @param list
     * @param fieldName
     * @return
     */
    public static Long[] toOneFieldValuesToLong(List<?> list,String fieldName){
        
        Long[] items = new Long[list.size()];
        for (int i = 0; i < list.size(); i++) {
            Object item = list.get(i);
            Long val = (Long)DomainFieldReflectUtil.getFieldValue(item, fieldName);
            items[i] = val;
        }
        return items;
    }
    
}
